/*
 * @Author: your name
 * @Date: 2020-09-18 09:31:02
 * @LastEditTime: 2020-11-04 15:40:09
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \supplyweb\src\main.js
 */
import 'babel-polyfill'
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import '@/permission' // permission control
import Antd from 'ant-design-vue'
import 'ant-design-vue/dist/antd.less'
import VueI18n from 'vue-i18n'
import LangENUS from './common/lang/en-us'
import LangZHCN from './common/lang/zh-cn'
import '@/assets/css/style.less'
import '@/assets/iconfont/iconfont.css'
import VueDirectiveImagePreviewer from 'vue-directive-image-previewer'
import 'vue-directive-image-previewer/dist/assets/style.css'
import 'animate.css'
Vue.use(VueDirectiveImagePreviewer)
import Viewer from 'v-viewer'
import 'viewerjs/dist/viewer.css'
import echarts from 'echarts'
import htmlToPdf from '@/components/utils/htmlToPdf'
Vue.use(htmlToPdf)
Vue.use(Viewer)
Viewer.setDefaults({
    Options: { 'inline': true, 'button': true, 'navbar': true, 'title': true, 'toolbar': true, 'tooltip': true, 'movable': true, 'zoomable': true, 'rotatable': true, 'scalable': true, 'transition': true, 'fullscreen': true, 'keyboard': true, 'url': 'data-source' }
})


Vue.use(Antd)
Vue.use(VueI18n)

Vue.prototype.$setLoading = function (props) {
    if (typeof props === 'boolean') props = { spinning: props }
    if (Object.prototype.toString.call(props) !== '[object Object]') props = {}
    console.log('this.$app', this.$app);

    this.$app.loadingProps = {
        tip: '加载中...',
        ...props
    }
}

const i18n = new VueI18n({
    locale: 'zh-cn',// 定义默认语言为中文 
    messages: {
        'en-us': LangENUS,
        'zh-cn': LangZHCN
    }
})
// 引入echarts
Vue.prototype.$echarts = echarts
Vue.config.productionTip = false

// 注册图片加载指令
Vue.directive('real-img', async function (el, binding) {
    let imgURL = binding.value
    if (imgURL) {
        let exist = await imageExists(imgURL)
        if (exist) {
            el.setAttribute('src', imgURL)
        }
    }
})
Vue.mixin({
    methods: {
        getImageUrl (file_name) {
            return `${file_name}`
        },

        wengeGetImageUrl (file_name) {
            return `/wenge/microservice-supply-consumer-web/minio/download?cache=true&file_name=${file_name}` // 如需适配自己服务请另起方法或者增加参数
        }
    }
})
// 检测图片是否存在
let imageExists = function (url) {
    return new Promise(resolve => {
        let img = new Image()
        img.onload = function () {
            if (this.complete == true) {
                resolve(true)
                img = null
            }
        }
        img.onerror = function () {
            resolve(false)
            img = null
        }
        img.src = url
    })
}




new Vue({
    router,
    store,
    i18n,
    render: h => h(App)
}).$mount('#app')
